package com.zcn.io.web.controller;

import com.zcn.io.common.pojo.CommonResult;
import com.zcn.io.web.api.dto.DictDto;
import com.zcn.io.web.api.entity.User;
import com.zcn.io.web.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc:
 * @author: 202438 邱建伟
 * @date: 2024/10/20 21:58
 * @Copyright (c) 2024, 江苏金恒信息科技股份有限公司
 */
@RestController
@AllArgsConstructor
@RequestMapping("/userManage")
public class UserController {

    private final UserService userService;

    @GetMapping("/list")
    @PreAuthorize("hasAnyAuthority('super_man')")
    public CommonResult<List<User>> list() {
        return CommonResult.success(userService.list());
    }

    @PostMapping("/save")
    @PreAuthorize("hasAnyAuthority('super_man')")
    public CommonResult<String> save(@RequestBody User user) {
        userService.save(user);
        return CommonResult.success("保存成功");
    }

    @GetMapping("/dict")
    public CommonResult<List<DictDto>> dict() {
        return CommonResult.success(userService.dict());
    }
}
